define(function (require) {
var zsApp = require('app');
zsApp.controller( 'loginController',["$scope", "$http", "$state","$rootScope","$cookieStore", "$timeout",function( $scope,$http, $state,$rootScope,$cookieStore,$timeout){
	
	$scope.verifyCode = {};
	$http({		
		url    : $scope.zsUrl+'digitalhome-boss/admin/pusers/getVerify?'+Math.random(),
		method : 'GET',
	}).then(function success(res) {
		console.log(res);
		$("#imgVerify").attr("src",res.data.imageParam);		
		$scope.verifyCode = res.data.verifyCode;	
	},function error(err){
		
	});
	
	//确定新增（新增一条系统配置键数据）
	$scope.getVerify = function() {
		$http({		
			url    : $scope.zsUrl+'digitalhome-boss/admin/pusers/getVerify?'+Math.random(),
			method : 'GET',
		}).then(function success(res) {	
			$("#imgVerify").attr("src",res.data.imageParam);		
			$scope.verifyCode = res.data.verifyCode;		
		},function error(err){
		});
	}
	
	
	$scope.checkSum = function() {
			$scope.loginUsername = false;
			$scope.loginPassword = false;
			$scope.loginVerification = false;
			$scope.loginNull = false;
			 var inputStr = $scope.login_validationCode;	 
			 if(inputStr!=null && inputStr!=""){
			        inputStr = inputStr.toUpperCase();//将输入的字母全部转换成大写
			 }else{
				 $(".warn_text").text("请输入验证码");
			     $(".login_form_warn").css("display","block");
			 }	 
		
			 var loginData = {
						userName   : $scope.login_userName,
						password   : $scope.login_password,		
						verifyCodeHash: $scope.verifyCode,
						verifyCode: inputStr,		            
					}
					$http({
						url    : $scope.zsUrl+'digitalhome-boss/admin/pusers/login',
						method : 'POST',
						data   : loginData, /* 将JSON发送给服务器 */
							
					}).then(function success(res) {
						console.log(res.data);	
						$scope.loginMessage = res.data.message;
						//用户 密码  验证码 后台验证
						if(res.data.result_code == '2222'){
							$scope.loginUsername = res.data.message;
						}else if(res.data.result_code == '1111'){
							$scope.loginPassword = res.data.message;
						}else if(res.data.result_code == '4444'){
							$scope.loginNull = res.data.message;
						}else if(res.data.result_code == '9999'){
							$scope.loginVerification = res.data.message;
						}else if(res.data.result_code == '0000'){
							$scope.loginUsername = false;
							$scope.loginPassword = false;
							$scope.loginVerification = false;
							$scope.loginNull = false;
						}
						if(undefined == res.data.back_url){
							$scope.getVerify();							
						}else{	
							var backUrl = res.data.back_url.toString();
							if(backUrl == 'login'){
								$scope.getVerify();
							}else{
								$state.go(backUrl,{},{cache: true});
							}
							//提示错误信息
						}
						
					},
					function error(err){
						$scope.getVerify();					
					});
	}
}]);
});